/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.CourseClass;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Courseinfo.findAll", query = "SELECT c FROM Courseinfo c"),
    @NamedQuery(name = "Courseinfo.findByCoursename", query = "SELECT c FROM Courseinfo c WHERE c.coursename = :coursename"),
    @NamedQuery(name = "Courseinfo.findByIdentifier", query = "SELECT c FROM Courseinfo c WHERE c.identifier = :identifier"),
    @NamedQuery(name = "Courseinfo.findByCoursecoordinator", query = "SELECT c FROM Courseinfo c WHERE c.coursecoordinator = :coursecoordinator"),
    @NamedQuery(name = "Courseinfo.findByDegreeprogram", query = "SELECT c FROM Courseinfo c WHERE c.degreeprogram = :degreeprogram")})
public class Courseinfo implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Size(max = 20)
    @Column(length = 20)
    private String coursename;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String identifier;
    @Size(max = 20)
    @Column(length = 20)
    private String coursecoordinator;
    @Size(max = 20)
    @Column(length = 20)
    private String degreeprogram;
    @ManyToMany(mappedBy = "courseinfoCollection")
    private Collection<Degreeprogram> degreeprogramCollection;
    @OneToMany(mappedBy = "courseidentifier")
    private Collection<Courseoutcome> courseoutcomeCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "courseinfo")
    private Collection<Altcoursecoordinators> altcoursecoordinatorsCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "courseinfo")
    private Collection<Courseoffering> courseofferingCollection;

    public Courseinfo() {
        degreeprogramCollection = new ArrayList();
        courseoutcomeCollection = new ArrayList();
        altcoursecoordinatorsCollection = new ArrayList();
        courseofferingCollection = new ArrayList();
    }

    public Courseinfo(String identifier) {
        this.identifier = identifier;
        degreeprogramCollection = new ArrayList();
        courseoutcomeCollection = new ArrayList();
        altcoursecoordinatorsCollection = new ArrayList();
        courseofferingCollection = new ArrayList();
    }

    public String getCoursename() {
        return coursename;
    }

    public void setCoursename(String coursename) {
        this.coursename = coursename;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getCoursecoordinator() {
        return coursecoordinator;
    }

    public void setCoursecoordinator(String coursecoordinator) {
        this.coursecoordinator = coursecoordinator;
    }

    public String getDegreeprogram() {
        return degreeprogram;
    }

    public void setDegreeprogram(String degreeprogram) {
        this.degreeprogram = degreeprogram;
    }

    @XmlTransient
    public Collection<Degreeprogram> getDegreeprogramCollection() {
        return degreeprogramCollection;
    }

    public void setDegreeprogramCollection(Collection<Degreeprogram> degreeprogramCollection) {
        this.degreeprogramCollection = degreeprogramCollection;
    }

    @XmlTransient
    public Collection<Courseoutcome> getCourseoutcomeCollection() {
        return courseoutcomeCollection;
    }

    public void setCourseoutcomeCollection(Collection<Courseoutcome> courseoutcomeCollection) {
        this.courseoutcomeCollection = courseoutcomeCollection;
    }

    @XmlTransient
    public Collection<Altcoursecoordinators> getAltcoursecoordinatorsCollection() {
        return altcoursecoordinatorsCollection;
    }

    public void setAltcoursecoordinatorsCollection(Collection<Altcoursecoordinators> altcoursecoordinatorsCollection) {
        this.altcoursecoordinatorsCollection = altcoursecoordinatorsCollection;
    }

    @XmlTransient
    public Collection<Courseoffering> getCourseofferingCollection() {
        return courseofferingCollection;
    }

    public void setCourseofferingCollection(Collection<Courseoffering> courseofferingCollection) {
        this.courseofferingCollection = courseofferingCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Courseinfo)) {
            return false;
        }
        Courseinfo other = (Courseinfo) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Courseinfo[ identifier=" + identifier + " ]";
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> associatedClasses = new ArrayList();
        associatedClasses.add((List) this.altcoursecoordinatorsCollection);
        associatedClasses.add((List) this.courseofferingCollection);
        associatedClasses.add((List) this.courseoutcomeCollection);
        associatedClasses.add((List) this.degreeprogramCollection);
        return associatedClasses;
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if (associated.equals(Altcoursecoordinators.class.getSimpleName())) {
            return (List) this.altcoursecoordinatorsCollection;
        }
        if (associated.equals(Courseoffering.class.getSimpleName())) {
            return (List) this.courseofferingCollection;
        }
        if (associated.equals(Courseoutcome.class.getSimpleName())) {
            return (List) this.courseoutcomeCollection;
        }
        if (associated.equals(Degreeprogram.class.getSimpleName())) {
            return (List) this.degreeprogramCollection;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        if (gt instanceof CourseClass) {
            CourseClass cc = (CourseClass) gt;
            this.coursecoordinator = cc.getCoursecoordinator();
            this.coursename = cc.getCoursename();
            this.degreeprogram = cc.getDegreeProgram();
            this.identifier = cc.getIdentifier();
        }
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if (ge instanceof Altcoursecoordinators) {
            this.altcoursecoordinatorsCollection.add((Altcoursecoordinators) ge);
        } else if (ge instanceof Courseoffering) {
            this.courseofferingCollection.add((Courseoffering) ge);
        } else if (ge instanceof Courseoutcome) {
            this.courseoutcomeCollection.add((Courseoutcome) ge);
        } else if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.add((Degreeprogram) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Altcoursecoordinators) {
            this.altcoursecoordinatorsCollection.remove((Altcoursecoordinators) ge);
        } else if (ge instanceof Courseoffering) {
            this.courseofferingCollection.remove((Courseoffering) ge);
        } else if (ge instanceof Courseoutcome) {
            this.courseoutcomeCollection.remove((Courseoutcome) ge);
        } else if (ge instanceof Degreeprogram) {
            this.degreeprogramCollection.remove((Degreeprogram) ge);
        }
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public String getIdentifier2() {
        return this.identifier;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }
}
